package com.shunli.cterminal.model.dto;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.examples.core.enums.YesOrNoEnum;
import com.examples.core.exception.ServiceException;
import com.shunli.cterminal.model.code.CterminalResultCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 描述
 * </p>
 *
 * @author daodao
 * @since 2025-04-29 17:05
 */
@Data
public class PolicyGoodsAndPlatformJsonDTO implements Serializable {
    private static final long serialVersionUID = -8724795874147330936L;

    @Schema(description = "是否全选 1:全部，0:部分 (YesOrNoEnum)")
    private String allEnable;
    @Schema(description = "包含 1:包含，0:不包含 (YesOrNoEnum)")
    private String containEnable;
    @Schema(description = "id列表")
    private List<String> idList;
    @Schema(description = "id对应的名称列表")
    private List<String> idNameList;


    public static String getDefaultPolicyGoodsAndPlatformJson() {
        PolicyGoodsAndPlatformJsonDTO platformJsonDTO = new PolicyGoodsAndPlatformJsonDTO();
        platformJsonDTO.setAllEnable(YesOrNoEnum.YES.getCode());
        return JSONObject.toJSONString(platformJsonDTO);
    }

    public static void checkParams(PolicyGoodsAndPlatformJsonDTO platformJsonDTO) {
        if (ObjectUtil.isNull(platformJsonDTO)) {
            throw new ServiceException(CterminalResultCode.PARAMS_EMPTY);
        }
        if (StrUtil.isBlank(platformJsonDTO.getAllEnable())) {
            throw new ServiceException(CterminalResultCode.PARAMS_EMPTY);
        }
        if (StrUtil.equals(YesOrNoEnum.NO.getCode(), platformJsonDTO.getAllEnable())) {
            if (StrUtil.isBlank(platformJsonDTO.getContainEnable()) || CollectionUtil.isEmpty(platformJsonDTO.getIdList())) {
                throw new ServiceException(CterminalResultCode.PARAMS_EMPTY);
            }
        }
    }
}
